var uriUtil = require('../../utils/uri.js');

Page({

  data: {
    baseUrl: uriUtil.BASE_URL,
    userInfo: {
      username: '',
      password: ''
    }
  },
  //输入处理
  onInput:function (e) {
    let typename = e.currentTarget.dataset.typename;
    let value = e.detail.value;
    let userInfo = this.data.userInfo;
    userInfo[typename] = value;
    this.setData({
      userInfo: userInfo
    });
  },
  //登录提交
  login: function () {
    let that = this;
    let userInfo = that.data.userInfo;
    let url = uriUtil.BASE_URL+uriUtil.login;
    wx.request({
       url: url,
       data:userInfo,
       method: 'get',
       success: function (res) {
          console.log(res);
         if(1){
          wx.showToast({
            title: '登录成功',
          }); 
          uriUtil.setUserNum(res.data[0].jianchi)
          console.log(res.data[0].jianchi);
          uriUtil.setUserInfo(res.data[0]);
          wx.switchTab({
            url: '../index/index',
          })
         }
        
       
       }
    })
  },
  //跳转到注册页面
  regist: function(){
    wx.navigateTo({
      url: '../regist/regist',
    })
  }
})